home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / scripts / point_shadowmaps.javascript < prev    next >
Encoding:
Text File  |  2004-07-23  |  2.3 KB  |  77 lines

  1. //javascript
  2.  
  3. /// Boilerplate to determine which document to modify ...
  4. function FindDocument(ScriptName)
  5. {
  6.     if(Document)
  7.             return Document;
  8.     else
  9.             {
  10.                     if(Application.documents.length == 1)
  11.                             return Application.documents[0];
  12.                     else if(Application.documents.length == 0)
  13.                             Application.ui.ErrorMessage("You must have an open document to run this script!", ScriptName + ":");
  14.                     else
  15.                             Application.ui.ErrorMessage("Not sure which document to use ... try using the desired document's Document Window > Tools > Play Script.", ScriptName + ":");
  16.             }
  17.             
  18.     return null;
  19. }
  20.  
  21. function CreateShadowMap(Document, Name)
  22. {
  23.     var shadow_map = Document.CreateObject("ShadowMap");
  24.     shadow_map.name = Name;
  25.  
  26.     return shadow_map;
  27. }
  28.  
  29. var gtkml =
  30.     '<gtkml>' +
  31.         '<window type="toplevel" title="point_shadowmaps">' +
  32.             '<vbox homogeneous="false">' +
  33.                 '<hbox homogeneous="false" expand="true">' +
  34.                     '<label labelpadding="4">Enter root name for Shadow Maps:</label>' + 
  35.                     '<entry name="name">Shadow Map</entry>' +
  36.                 '</hbox>' + 
  37.                 '<hbuttonbox layout="end">' +
  38.                     '<button>OK' + 
  39.                         '<event signal="clicked" name="ok"/>' + 
  40.                     '</button>' +
  41.                     '<button>Cancel' +
  42.                         '<event signal="clicked" name="cancel"/>' +
  43.                     '</button>' +
  44.                 '</hbuttonbox>' +
  45.             '</vbox>' +
  46.         '</window>' +
  47.     '</gtkml>';
  48.  
  49. document = FindDocument("point_shadowmaps");
  50. if(document)
  51.     {
  52.         dialog = new GTKMLContainer(gtkml);
  53.         if(dialog.DoModal())
  54.             {
  55.                 // Record undo/redo data ...
  56.                 document.StartChangeSet();
  57.  
  58.                 var root_name = dialog.Field("name");
  59.                 var front = CreateShadowMap(document, root_name + " Front");
  60.                 var back = CreateShadowMap(document, root_name + " Back");
  61.                 var left = CreateShadowMap(document, root_name + " Left");
  62.                 var right = CreateShadowMap(document, root_name + " Right");
  63.                 var top = CreateShadowMap(document, root_name + " Top");
  64.                 var bottom = CreateShadowMap(document, root_name + " Bottom");
  65.  
  66.                 // Finish recording undo/redo data (no need to record the rest of our changes) ...
  67.                 document.FinishChangeSet("Create point shadowmaps");
  68.  
  69.                 back.orientation = [0, 180, 0];
  70.                 left.orientation = [0, 90, 0];
  71.                 right.orientation = [0, -90, 0];
  72.                 top.orientation = [90, 0, 0];
  73.                 bottom.orientation = [-90, 0, 0];
  74.             }
  75.     }
  76.  
  77.